import { DxLoadPanelComponent } from 'devextreme-angular';
import { Injectable } from '@angular/core';

@Injectable()
export class LoadService {
  public loadPanel: DxLoadPanelComponent;
  public ajaxLongTimer: number = 1000 * 60 * 30; // 默认三十分钟 // ajax最长时间
  constructor() { }
  public init(instance: DxLoadPanelComponent){
    this.loadPanel = instance;
  }
  public show(text: string = "正在加载", target: string = '.content'){
    if(this.loadPanel){
      this.loadPanel.message = text;
      this.loadPanel.position = {
        my: 'center',
        at: 'center',
        of: target
      };
      this.loadPanel.instance.show();
      setTimeout(
        () => {
          this.loadPanel.instance.hide();
        }, this.ajaxLongTimer
      )
    }
    
  }
  public hide(){
    if(this.loadPanel){
      this.loadPanel.instance.hide();
    }
  }

}
